/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ipti.br.tag.entity;

import java.util.Calendar;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.ipti.br.tag.util.CalendarUtil;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author root
 */

@Entity
public class UnityCalendar extends AbstractEntity{

    @Temporal(TemporalType.DATE)
    @Column(name="calendar_day")
    private Calendar calendarDay;

    @Temporal(TemporalType.TIME)
    @Column(name="initial_time")
    private Calendar initialTime;

    @Temporal(TemporalType.TIME)
    @Column(name="final_time")
    private Calendar finalTime;

    @Column(length=50, nullable=true)
    private String situation;

    @Lob
    @Column(nullable=true)
    private String obs;

    @ManyToOne
    @JoinColumn(name = "unity_id")
    private Unity unity;

    @ManyToOne
    @JoinColumn(name = "unitySchedule_id", nullable = false)
    private UnitySchedule unitySchedule;

    @ManyToOne
    @JoinColumn(name = "task_id", nullable = false)
    private Task task;

    @ManyToOne
    @JoinColumn(name = "discipline_id", nullable = false)
    private Discipline discipline;
    
    public UnityCalendar() {
    }

    @Override
    public void generateHash(){
        if(getId() == null){
            String unityCalendarHashString = ""
                    + ((this.getCalendarDay() != null) ? CalendarUtil.getFormatedDate(this.getCalendarDay()) : null)
                    + ((this.getUnity() != null) ? this.getUnity().getId() : null)
                    + ((this.getUnitySchedule() != null) ? this.getUnitySchedule().getId() : null)
                    + ((this.getTask() != null) ? this.getTask().getId() : null)
                    + ((this.getDiscipline() != null) ? this.getDiscipline().getId() : null);
            this.setId(Long.valueOf(EncryptionUtil.encrypt(unityCalendarHashString).hashCode()));
        }
    }

    public UnityCalendar(Calendar calendarDay, Calendar initialTime, Calendar finalTime, Unity unity, UnitySchedule unitySchedule, Task task, Discipline discipline) {
        this.calendarDay = calendarDay;
        this.initialTime = initialTime;
        this.finalTime = finalTime;
        this.unity = unity;
        this.unitySchedule = unitySchedule;
        this.task = task;
        this.discipline = discipline;
//        frequencyList = new ArrayList<Frequency>();
    }

    public UnityCalendar(Calendar calendarDay, Calendar initialTime, Calendar finalTime, String situation, String obs, Unity unity, UnitySchedule unitySchedule, Task task, Discipline discipline) {
        this.calendarDay = calendarDay;
        this.initialTime = initialTime;
        this.finalTime = finalTime;
        this.situation = situation;
        this.obs = obs;
        this.unity = unity;
        this.unitySchedule = unitySchedule;
        this.task = task;
        this.discipline = discipline;
//        frequencyList = new ArrayList<Frequency>();
    }

    public Calendar getCalendarDay() {
        return calendarDay;
    }

    public void setCalendarDay(Calendar calendarDay) {
        this.calendarDay = calendarDay;
    }

    public Task getTask() {
        return task;
    }

    public void setTask(Task task) {
        this.task = task;
    }

    public Discipline getDiscipline() {
        return discipline;
    }

    public void setDiscipline(Discipline discipline) {
        this.discipline = discipline;
    }

    public Calendar getFinalTime() {
        return finalTime;
    }

    public void setFinalTime(Calendar finalTime) {
        this.finalTime = finalTime;
    }

    public Calendar getInitialTime() {
        return initialTime;
    }

    public void setInitialTime(Calendar initialTime) {
        this.initialTime = initialTime;
    }

    public String getObs() {
        return obs;
    }

    public void setObs(String obs) {
        this.obs = obs;
    }

    public String getSituation() {
        return situation;
    }

    public void setSituation(String situation) {
        this.situation = situation;
    }

    public Unity getUnity() {
        return unity;
    }

    public void setUnity(Unity unity) {
        this.unity = unity;
    }

    public UnitySchedule getUnitySchedule() {
        return unitySchedule;
    }

    public void setUnitySchedule(UnitySchedule unitySchedule) {
        this.unitySchedule = unitySchedule;
    }
}
